package cruncher;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Random;

import utils.Logger;

public class FixingStrategy {
	double fixedSetProportion = 0.8; //in percentage of the variables set size
	Random rnd = new Random(System.currentTimeMillis());
	
	public FixingStrategy()
	{
	}
	
	public FixingStrategy(double proportion)
	{
		fixedSetProportion = proportion;
	}
	
	//TODO 
	//set priority [0,1] for every variable, sort them according to priority 
	public HashSet<Variable> getFixedSet(Solution sol) {
		Logger.INFO(String.format("Fixing %.2f %% variables", fixedSetProportion * 100));
		HashSet<Variable> fixed = new HashSet<Variable>();
		LinkedList<Variable> l = new LinkedList<Variable>();
		l.addAll(sol.getDecisionVariables());
		

		int fixedSetSize = (int)(l.size() * fixedSetProportion);
		int pos = 0;
        while(pos < fixedSetSize){
        	/*
            int randPos = rnd.nextInt(n);
            if (l.get(randPos).isInteger())
            {
            	fixed.add(l.get(randPos));
            }
            */
        	Variable next = l.get(pos++); 
            fixed.add(next);
            
        }

        return fixed;
	}

}
